/*
 * @(#)TeddyApplicationModel.java
 *
 * Copyright (c) 2007-2008 by the original authors of JHotDraw and all its
 * contributors. All rights reserved.
 *
 * You may not use, copy or modify this file, except in compliance with the 
 * license agreement you entered into with the copyright holders. For details
 * see accompanying license terms.
 */
package org.jhotdraw.samples.teddy;

import java.util.Collections;
import java.util.List;

import javax.swing.AbstractAction;
import javax.swing.ActionMap;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JMenu;
import javax.swing.JToolBar;

import org.jhotdraw.app.Application;
import org.jhotdraw.app.DefaultApplicationModel;
import org.jhotdraw.app.DefaultMenuBuilder;
import org.jhotdraw.app.MenuBuilder;
import org.jhotdraw.app.View;
import org.jhotdraw.app.action.ActionUtil;
import org.jhotdraw.app.action.file.PrintFileAction;
import org.jhotdraw.gui.JFileURIChooser;
import org.jhotdraw.samples.teddy.action.FindAction;
import org.jhotdraw.samples.teddy.action.ToggleLineNumbersAction;
import org.jhotdraw.samples.teddy.action.ToggleLineWrapAction;
import org.jhotdraw.samples.teddy.action.ToggleStatusBarAction;

/**
 * TeddyApplicationModel.
 * 
 * @author Werner Randelshofer
 * @version $Id: TeddyApplicationModel.java 717 2010-11-21 12:30:57Z rawcoder $
 */
public class TeddyApplicationModel extends DefaultApplicationModel {

	/** Creates a new instance. */
	public TeddyApplicationModel() {
	}

	@Override
	public ActionMap createActionMap(Application a, View v) {
		ActionMap m = super.createActionMap(a, v);
		AbstractAction aa;

		m.put(FindAction.ID, new FindAction(a, v));
		m.put(ToggleLineWrapAction.ID, new ToggleLineWrapAction(a, v));
		m.put(ToggleStatusBarAction.ID, new ToggleStatusBarAction(a, v));
		m.put(ToggleLineNumbersAction.ID, new ToggleLineNumbersAction(a, v));
		m.put(PrintFileAction.ID, null);

		return m;
	}

	@Override
	public void initView(Application a, View v) {
	}

	/** Creates the MenuBuilder. */
	@Override
	protected MenuBuilder createMenuBuilder() {
		return new DefaultMenuBuilder() {

			@Override
			public void addOtherViewItems(JMenu m, Application app, View v) {
				ActionMap am = app.getActionMap(v);
				JCheckBoxMenuItem cbmi;
				cbmi = new JCheckBoxMenuItem(am.get(ToggleLineWrapAction.ID));
				ActionUtil.configureJCheckBoxMenuItem(cbmi, am.get(ToggleLineWrapAction.ID));
				m.add(cbmi);
				cbmi = new JCheckBoxMenuItem(am.get(ToggleLineNumbersAction.ID));
				ActionUtil.configureJCheckBoxMenuItem(cbmi, am.get(ToggleLineNumbersAction.ID));
				m.add(cbmi);
				cbmi = new JCheckBoxMenuItem(am.get(ToggleStatusBarAction.ID));
				ActionUtil.configureJCheckBoxMenuItem(cbmi, am.get(ToggleStatusBarAction.ID));
				m.add(cbmi);
			}
		};
	}

	/**
	 * Creates toolbars for the application. This class returns an empty list -
	 * we don't want toolbars in a text editor.
	 */
	@Override
	public List<JToolBar> createToolBars(Application app, View p) {
		return Collections.emptyList();
	}

	@Override
	public JFileURIChooser createOpenChooser(Application app, View p) {
		JFileURIChooser chooser = new JFileURIChooser();
		chooser.setAccessory(new CharacterSetAccessory());
		return chooser;
	}

	@Override
	public JFileURIChooser createSaveChooser(Application app, View p) {
		JFileURIChooser chooser = new JFileURIChooser();
		chooser.setAccessory(new CharacterSetAccessory());
		return chooser;
	}
}
